<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Sound Machine</title>
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
    <link href="css/index.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="settings">Settings</div>
<div class="close">Close</div>
<div id="main" class="container-fluid">
    <div class="row">
        <div class="col-xs-12">
            <div class="speaker">
                <img src="img/speaker.png"/>
            </div>
            <h1>
                <img src="img/logo.png"/>
            </h1>
        </div>
    </div>
    <div class="row buttons">
        <div class="col-xs-3">
            <div class="button-sound" data-sound="ba-dum-tsss">
                <span class="button-icon" ></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="money">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="applause">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="burp">
                <span class="button-icon"></span>
            </div>
        </div>
    </div>
    <div class="row buttons">
        <div class="col-xs-3">
            <div class="button-sound" data-sound="crowd-laughing">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="fart">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="sad-trombone">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="money">
                <span class="button-icon"></span>
            </div>
        </div>
    </div>
    <div class="row buttons">
        <div class="col-xs-3">
            <div class="button-sound" data-sound="ba-dum-tsss">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="money">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="ba-dum-tsss">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="money">
                <span class="button-icon"></span>
            </div>
        </div>
    </div>
    <div class="row buttons">
        <div class="col-xs-3">
            <div class="button-sound" data-sound="ba-dum-tsss">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="money">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="ba-dum-tsss">
                <span class="button-icon"></span>
            </div>
        </div>
        <div class="col-xs-3">
            <div class="button-sound" data-sound="money">
                <span class="button-icon"></span>
            </div>
        </div>
    </div>
</div>
<script type="application/javascript" charset="utf-8">
		const {ipcRenderer} = require('electron');
		var soundButtons = document.querySelectorAll('.button-sound');
		var settingsEl = document.querySelector('.settings');
		var closeEl = document.querySelector('.close');
			for (var i = 0; i < soundButtons.length; i++) {
	    			var soundButton = soundButtons[i];
	    			var soundName = soundButton.attributes['data-sound'].value;
	 			   prepareButton(soundButton, soundName);
			}
			
			
	function prepareButton(buttonEl, soundName) {
	    buttonEl.querySelector('span').style.backgroundImage = 'url("img/icons/' + soundName + '.png")';
	    var audio = new Audio(__dirname + '/wav/' + soundName + '.wav');
	    buttonEl.addEventListener('click', function () {
	        audio.currentTime = 0;
	        audio.play();
	    });
}

settingsEl.addEventListener('click', function () {
  ipcRenderer.send('open-settings-window');
    
});


closeEl.addEventListener('click', function () {
    ipcRenderer.send('close-main-window');
});

ipcRenderer.on('global-shortcut', (event, arg) => {
		var event = new MouseEvent('click');
  		soundButtons[arg].dispatchEvent(event);
});



</script>
</body>
</html>
